package com.api.wall.getdocumentevents;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IWallApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.CollectionResultApi;
import com.zyncro.api.model.EventApi;
import com.zyncro.api.model.EventApiType;
import com.zyncro.api.model.EventViewApiType;

@ContextConfiguration(locations = { "classpath:/wall/wall-static.xml" })
public class GetDocumentEvents extends AbstractApiTest {

	@Value("#{group_toGetDocument[participant].appId}")
	private String userUrn;

	@Value("#{group_toGetDocument[participant].password}")
	private String userPassword;

	@Value("#{group_toGetDocument.urn}")
	private String groupUrn;

	@Value("#{group_toGetDocument.documentUrn}")
	private String documentUrn;

	@Value("#{group_toGetDocument.totalFeeds}")
	private int totalFeeds;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void testGetDocumentEventsAll() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;
		List<EventApiType> eventTypes = null;
		boolean includeHtml = false;
		EventViewApiType viewType = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getDocumentEvents(groupUrn, documentUrn, date,
				itemsCount, eventTypes, includeHtml, includeProperties, viewType);

		Assert.assertEquals(result.getElements().size(), totalFeeds, "Total document feeds");
	}

	@Test
	public void testGetDocumentEventsType() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;

		List<EventApiType> eventTypes = new ArrayList<EventApiType>();
		eventTypes.add(EventApiType.DOCUMENTS_ADDED);

		boolean includeHtml = false;
		EventViewApiType viewType = null;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getDocumentEvents(groupUrn, documentUrn, date,
				itemsCount, eventTypes, includeHtml, includeProperties, viewType);

		Assert.assertEquals(result.getElements().size(), 1, "Event type document added feed");
	}

	@Test
	public void testGetDocumentEventsViewType() throws ZyncroApiException {

		String date = null;
		int itemsCount = 0;

		List<EventApiType> eventTypes = null;

		boolean includeHtml = false;
		EventViewApiType viewType = EventViewApiType.CONVERSATION;
		boolean includeProperties = false;

		CollectionResultApi<EventApi> result = getApi().getService(IWallApiService.class).getDocumentEvents(groupUrn, documentUrn, date,
				itemsCount, eventTypes, includeHtml, includeProperties, viewType);

		Assert.assertEquals(result.getElements().size(), totalFeeds, "Total document feeds");
	}
}
